/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-03-16     86188       the first version
 */
#ifndef APPLICATIONS_HEADER_FILE_FLY_MAIN_H_
#define APPLICATIONS_HEADER_FILE_FLY_MAIN_H_

#include "imu.h"

#define TASK_EVENT_z_finish      (1 << 3)
#define TASK_EVENT_pos_finish    (1 << 5)
#define TASK_EVENT_x_finish      (1 << 6)
#define TASK_EVENT_y_finish      (1 << 7)
#define TASK_EVENT_yaw_finish    (1 << 8)
#define TASK_EVENT_xy_finish     (1 << 9)

typedef struct
{
    float x;
    float y;
    float z;
    float yaw;
} vector;
typedef struct
{
    float x;
    float y;
} vector2;
typedef struct
{
    float x;
    float y;
    float z;
} vector3;
typedef struct
{
    uint8_t x;
    uint8_t y;
    uint8_t z;
    uint8_t yaw;
} DataMask;
typedef union
{
    struct
    {
        vector2  fencepoint[4];
        float fencepointLZ;
        float fencepointHZ;
        vector3  home;
    };
    float bytes[13];
}Fence_point;
typedef struct
{
    uint8_t enable;
    DataMask Valid;

    Fence_point Fpoint;
    uint8_t priority;
} Fence_contral;
typedef struct
{
    uint8_t enable;
    DataMask Valid;
    DataMask lock;

    uint16_t* rc_dat;
    uint8_t priority;
} RC_contral;
typedef union
{
    struct
    {
        vector3 point[4];
    };
    float bytes[12];
}Way_point;
typedef struct
{
    uint8_t enable;
    DataMask Valid;

    vector E_pos;
    uint16_t xy_rate;
    uint16_t z_rate;
    Way_point WayPoint;
    uint8_t priority;
} AUTO_Order;

typedef struct
{
    uint8_t enable;

    uint16_t distance;
    uint8_t priority;
} distance_contral;

typedef struct
{
    RC_contral RC;
    AUTO_Order AUTO;
    Fence_contral Fence;
} Ctrl_Source;

typedef struct
{
    uint8_t x;
    uint8_t y;
    uint8_t z;
    uint8_t yaw;
    uint8_t x_speed;
    uint8_t y_speed;
    uint8_t z_speed;
    uint8_t yaw_speed;
} centre_priority;
enum
{
    performing,
    finished,
};
typedef struct
{
    vector speed;
    centre_priority priority;
    DataMask    finish;
} Ctrl_Package;
typedef struct
{
    Ctrl_Package Ctrl;
    vector       nowPos;
    vector       staticPos;
    Axis2f       zeroPoint;

    vector       expectPos;
    float        expect_Vxy;
    float        expect_Vz;
    float        expect_dyaw;
    Ctrl_Source  CtrlSource;
} Task_HandleTypedef;
extern Task_HandleTypedef Task_Handle;

void task_stream(void* parameter);
void ctrl_stream(void* parameter);

#endif /* APPLICATIONS_HEADER_FILE_FLY_MAIN_H_ */
